package org.jackysoft.interceptor;

import java.lang.reflect.Method;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.functors.NotNullPredicate;
import org.jackysoft.annotations.ActionRequestMethod;
import org.jackysoft.annotations.MethodInceptor;
import org.jackysoft.util.CollectionUtils;
import org.springframework.web.servlet.ModelAndView;

@MethodInceptor(method = ActionRequestMethod.creates)
public class CreatesInterceptor extends AbstractInterceptor {

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {

		Method createBean = service.getClass().getMethod("create",
				java.util.Collection.class);
		CollectionUtils.filter((Collection<?>) beans,
				NotNullPredicate.getInstance());
		createBean.invoke(service, beans);
	}

}
